//
// variables
var httpobject = null;

function getobj(id)
{
	return document.getElementById(id);
}

function docall(method, url, param)
{
	httpobject = getHTTPObject();
	if(httpobject!=null)
	{
		httpobject.onreadystatechange = callback;
		httpobject.open(method, url+"?"+param, true);
		httpobject.send(null);
		getobj('divstatus').innerHTML = "<p>wait for response...</p>";
		getobj('divbody1').innerHTML=getobj('overlay2').innerHTML;//loading...
	}
}
function docall2(method, url, param)
{
	httpobject = getHTTPObject();
	if(httpobject!=null)
	{
		httpobject.onreadystatechange = callback2;
		httpobject.open(method, url+"?"+param, true);
		httpobject.send(null);
		getobj('divstatus').innerHTML = "<p>wait for response...</p>";
	}
}

var docall3_docobj = null;
function docall3(url, param, obj)
{//later...
	docall3_docobj = obj;
	docall3_docobj.innerHTML = getobj('overlay2').innerHTML;
	httpobject = getHTTPObject();
	if(httpobject!=null)
	{
		httpobject.open("POST", url, true);
		
		httpobject.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		httpobject.setRequestHeader("Content-length", param.length);
		httpobject.setRequestHeader("Connection", "close");
		
		httpobject.onreadystatechange = function()
		{
			if(httpobject.readyState==4 && httpobject.status==200)
			{
				docall3_docobj.innerHTML = httpobject.responseText;
			}
		};
		httpobject.send(param);
	}
}
function callback()
{
	getobj('divbody1').innerHTML = "";
	getobj('divstatus').innerHTML = "";
	 if(httpobject.readyState==4)
	 {//loaded
	 	if(httpobject.status==200)//ok
	 	{
	 		getobj('divbody1').innerHTML = httpobject.responseText;
	 	}else
	 	{
	 		getobj('divstatus').innerHTML = "failed to get a response";
	 	}
	 }
	
	getobj("overlay2").style.display="none";
}
function callback2()
{
	getobj('divbody2').innerHTML = "";
	getobj('divstatus').innerHTML = "";
	if(httpobject.readyState==4)
	{//loaded
		if(httpobject.status==200)//ok
			getobj('divbody2').innerHTML = httpobject.responseText;
		else
	 	{
	 		getobj('divstatus').innerHTML = "failed to get a response";
	 	}
	}
}
function getHTTPObject()
{

	if(window.ActiveXObject)
	{
		try
		{
			return new ActiveXObject ("Msxm12.XMLHTTP");
		}catch(e)
		{
			try
			{
				return new ActiveXObject ("Microsoft.XMLHTTP");
			}catch(e2)
			{
				return null;
			}
		}
	}else if(window.XMLHttpRequest)
		return new XMLHttpRequest();
	else
		return null;
}

